package com.jason.happy.application;

import android.app.Application;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.jason.happy.application.config.ImageFrescoConfiguration;
import com.jason.happy.common.utils.ImageManager;
import com.jason.happy.common.utils.image.strategy.impl.FrescoImageStrategy;
import com.jason.lib.netowrk.RetrofitAPI;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.FormatStrategy;
import com.orhanobut.logger.Logger;
import com.orhanobut.logger.PrettyFormatStrategy;

import org.xutils.x;

import retrofit2.Retrofit;

/**
 * Created by hacker on 17-6-25.
 */

public class HappyApplication extends Application {

    public static final String TAG = "HappyApplication";

    @Override
    public void onCreate() {
        super.onCreate();

        initLogger(); //logger

        initFresco(); //fresco

        //initImage(); //image

        //initNetworkAPI(); //network

        initXutils(); //xutils
    }


    /**
     * init fresh framework for image
     */
    private void initFresco() {
        ImageFrescoConfiguration.initFresco(this);
    }

    /**
     * init logger framework
     */
    private void initLogger() {
        FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
                .showThreadInfo(true)
                .methodCount(30)
                .methodOffset(0)
                .tag(TAG)
                .build();
        Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy));
    }

    /**
     * init image utility class
     */
    private void initImage() {
        ImageManager.init(new FrescoImageStrategy());
    }


    private void initNetworkAPI() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("")
                .build();
        RetrofitAPI.getInstance().initRetrofit(retrofit);
    }


    /**
     * init xutils
     */
    private void initXutils(){
        x.Ext.init(this);
    }

}
